global __read
global __write
global __cpuspeed
global fork
global exit
global __waitpid
global yeld
global kill
global signal
global sleep
global sleep2
global wakeup
global getpid
global top
global stacklimit
global heaplimit
global open
global close
global newstdio
global setuName
global setgName
global finfo
global lseek
global fcount
global chdir
global mknode
global chmod
global format
global lchown
global add_key_listener	
global setpriority
global usemytty
global killzombies
global setname

global __get_cursor
global __set_cursor

SECTION .text

;funcion a la que retornan los procesos del main. empuja el valor de retorno al stack, y llama a exit.

main_ret:
	push eax
	call exit
	ret
	

;muchas funciones que empujan valores al stack, setean eax y llaman a la int 80h. para explicacion detallada
;leer del lado del kernel.

__read:
    	mov ecx, [esp+8]
	mov eax,3
	mov ebx, [esp+4]
	mov edx, [esp+12]
	int 80h
	ret

__write:
    	mov ecx, [esp+8]
	mov eax,4
	mov ebx, [esp+4]
	mov edx, [esp+12]
	int 80h
	ret	
	 
exit:
	 mov ebx, [esp+4]
	 mov eax,1
	 int 80h
	 ret

fork:
	 mov ebx, [esp+4]
	 mov ecx, main_ret
	 mov edx, [esp+8]
	 mov eax,2
	 int 80h
	 ret

__waitpid:
	mov ecx, [esp+4]
	 mov ebx, [esp+8]
	 mov eax,7
	 int 80h
	 ret
	 
	 
yeld:
	mov eax,0
	int 80h
	ret
	
kill:
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	mov eax,32
	int 80h
	ret
	
signal:
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	mov eax,48
	int 80h
	ret
	
sleep:
	mov eax, 162
	int 80h
	ret
	
sleep2:
	mov eax, 161
	int 80h
	ret
	
wakeup:
	mov ebx, [esp+4]
	mov eax, 163
	int 80h
	ret
	
__get_cursor:
	mov eax, 201
	int 80h
	ret
	
__set_cursor:
	mov eax, 202
	mov ebx, [esp+4]
	int 80h
	ret
	
getpid:
	mov eax,20
	int 80h
	ret
	
top:
	mov eax, 110
	mov ebx, [esp+4]
	int 80h
	ret
	
stacklimit:
	mov eax, 111
	mov ebx, [esp+4]
	int 80h
	ret
	
heaplimit:
	mov eax, 112
	mov ebx, [esp+4]
	int 80h
	ret
	
open:
	mov eax, 5
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	int 80h
	ret

close:	
	mov eax, 6
	mov ebx, [esp+4]
	int 80h
	ret

newstdio:
	mov eax,52
	int 80h
	ret
	
setuName:
	mov eax, 23
	mov ebx, [esp+4]
	int 80h
	ret
	
setgName:
	mov eax, 46
	mov ebx, [esp+4]
	;int 80h
	ret

finfo:
	mov eax, 55
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	int 80h
	ret
	
fcount:
	mov eax, 56
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	int 80h
	ret

lseek:
	mov eax, 19
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	int 80h
	ret
	
chmod:
	mov eax, 15
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	int 80h
	ret
	
lchown:
	mov eax, 16
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	mov edx, [esp+12]
	int 80h
	ret
	
chdir:
	mov eax, 12
	mov ebx, [esp+4]
	int 80h
	ret
	
format:
	mov eax, 199
	int 80h
	ret
	
mknode:
	mov eax,14
	mov ebx, [esp+4]
    	mov ecx, [esp+8]
	mov edx, [esp+12]
	int 80h
	ret
	
add_key_listener:
	mov eax,198
	mov ebx, [esp+4]
    	mov ecx, [esp+8]
	mov edx, [esp+12]
	int 80h
	ret
	
setpriority:
	mov eax,97
	mov ebx, [esp+4]
	int 80h
	ret

usemytty:
	mov eax,200
	int 80h
	ret
	
killzombies:
	mov eax,203
	int 80h
	ret
	

setname:
	mov eax, 204
	mov ebx, [esp+4]
	mov ecx, [esp+8]
	int 80h
	ret

